import agconnect from '@hw-agconnect/api-ohos';
import "@hw-agconnect/core-ohos";
import "@hw-agconnect/function-ohos";

import {
  EmailAuthProvider,
  VerifyCodeAction,
  EmailUserBuilder,
  VerifyCodeSettingBuilder,
  AGConnectAuth
} from "@hw-agconnect/auth-ohos";

// 注意云函数调用方式，wrap里面填充的是http触发器的触发url
// 相关文档可以参考 https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/harmonyos-arkts-call-func-0000001633454686

// 添加银行卡
export async function addBankCard(payload) {
  const functionCallable = agconnect.function().wrap("add-card-$latest")
  const result = await functionCallable.call({
    action: 'add',
    payload
  })
  return result.getValue()
}

// 查询银行卡
export async function queryBankCard(payload) {
  const functionCallable = agconnect.function().wrap("add-card-$latest")
  const result = await functionCallable.call({
    action: 'query',
    payload
  })
  return result.getValue()
}


// 获取用户信息
export async function queryUser(payload) {
  const functionCallable = agconnect.function().wrap("user-$latest")
  const result = await functionCallable.call({
    action: 'query',
    payload
  })
  return result.getValue()
}

// 添加用户信息
export async function addUser(payload) {
  const functionCallable = agconnect.function().wrap("user-$latest")
  const result = await functionCallable.call({
    action: 'add',
    payload
  })
  return result.getValue()
}


// 修改用户信息
export async function patchUser(payload) {
  const functionCallable = agconnect.function().wrap("user-$latest")
  const result = await functionCallable.call({
    action: 'patch',
    payload
  })
  return result.getValue()
}

// 获取支付记录
export async function queryPayRecords(payload) {
  const functionCallable = agconnect.function().wrap("pay-records-$latest")
  const result = await functionCallable.call({
    action: 'query',
    payload
  })
  return result.getValue()
}

// 查询总出入帐
export async  function queryPayRecordsTotal(payload) {
  const functionCallable = agconnect.function().wrap("pay-records-$latest")
  const result = await functionCallable.call({
    action: 'queryTotal',
    payload
  })
  return result.getValue()
}

// 进行支付
export async function doPay(payload) {
  const functionCallable = agconnect.function().wrap("pay-records-$latest")
  const result = await functionCallable.call({
    action: 'add',
    payload
  })
  return result.getValue()
}